<?php

namespace App\Services;

use App\Models\User;

class ExpiredService
{
    public $user;

    public function __construct($user_id)
    {
        $this->user = User::findOrFail($user_id);
    }

    public function addDays($days){
        $add_seconds = $days * 60 * 60 * 24;
        $end_time = $this->user->expired_at;
        if ($end_time < strtotime('today')) {
            $expired_at = strtotime('tomorrow') + $add_seconds;
        } else {
            $expired_at = $end_time + $add_seconds;
        }

        $this->user->update(['expired_at' => $expired_at]);
    }
}
